//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    curNav: 'home',
    curTab:'optional',
    background: ['../../static/images/banner.jpg', '../../static/images/banner.jpg', '../../static/images/banner.jpg'],
    redPool: [{
      id: 1,
      checked: false,
    }, {
      id: 2,
      checked: false,
    }, {
      id: 3,
      checked: false,
    }, {
      id: 4,
      checked: false,
    }, {
      id: 5,
      checked: false,
    }, {
      id: 6,
      checked: false,
    }, {
      id: 7,
      checked: false,
    }, {
      id: 8,
      checked: false,
    }, {
      id: 9,
      checked: false,
    }, {
      id: 10,
      checked: false,
    }],
    bluePool: [{
      id: 1,
      checked: false,
    }, {
      id: 2,
      checked: false,
    }, {
      id: 3,
      checked: false,
    }, {
      id: 4,
      checked: false,
    }, {
      id: 5,
      checked: false,
    }, {
      id: 6,
      checked: false,
    }, {
      id: 7,
      checked: false,
    }, {
      id: 8,
      checked: false,
    }, {
      id: 9,
      checked: false,
    }, {
      id: 10,
      checked: false,
    }],
    bulePool: [],
    chooseCount:3,    //规定可选几组号
    chooseMaxRed:6,   
    isCheckRed:true,
    curChooseRed:[],
    curChooseBlue: '',
    lottoArray:[]    //已选择的双色球数组
  
  },
  
  //
  checkboxChange: function (e) {
    let redNo = e.detail.value;
    let redPool = this.data.redPool.map(item => {
      item.checked = redNo.includes(`${item.id}`) ? true :false;
      return item;
    });

    this.setData({
      isCheckRed: redNo.length >= this.data.chooseMaxRed ? false :true ,
      curChooseRed: redNo,
      redPool: redPool
    })

    console.log('你选择红号为：', redNo)
  },

  //获取蓝号值
  radioChange: function (e) {
    const blueNo = e.detail.value;
    let bluePool = this.data.bluePool.map(item => {
      item.checked = item.id == blueNo ? true : false;
      return item;
    });

    this.setData({
      bluePool: bluePool,
      curChooseBlue: blueNo
    })
    console.log('你选择蓝号为：', blueNo)
  },

  handleClick(){
    if (this.data.lottoArray.length >= this.data.chooseCount){
      return;
    }

    if (this.data.curChooseRed.length === this.data.chooseMaxRed && this.data.curChooseBlue){
      let lottoArray = this.data.lottoArray;
      lottoArray.push([...this.data.curChooseRed, this.data.curChooseBlue]);
      let redPool = this.data.redPool.filter(item => {
        item.checked = false;
        return item
      })
      let bluePool = this.data.bluePool.filter(item => {
        item.checked = false;
        return item
      })
      this.setData({
        redPool: redPool,
        bluePool: bluePool,
        lottoArray: lottoArray,
        curChooseRed:[],
        curChooseBlue:"",
        isCheckRed: true
      });
      console.log(this.data.lottoArray);
    }
  },
  deleteLotto(e){
    const lottoArray = this.data.lottoArray.filter((item,i)=> i !== e.currentTarget.dataset.idx);
    this.setData({
      lottoArray: lottoArray
    });
  },
  tabChange(event) {
    this.setData({
      curTab: event.target.id
    });
  },

  navChange({ detail }) {
    this.setData({
      curNav: detail.key
    });
  },
})
